//
//  CYArcitleDetailsViewController.m
//  cyydt
//
//  Created by chu on 2019/1/21.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYArcitleDetailsViewController.h"
#import <WebKit/WebKit.h>
#import <JavaScriptCore/JavaScriptCore.h>
#import "CYCommentModel.h"

#import "CYZiXunTitleTableViewCell.h"
#import "CYZiXunXiangGuanSouSuoTableViewCell.h"
#import "CYZiXunXiangGuanGuangGaoTableViewCell.h"
#import "CYZiXunXiangGuanXiangMuTableViewCell.h"
#import "CYVideoDetail_ShipinTuiJianTableViewCell.h"
#import "CYVideoDetail_CommentTableViewCell.h"
#import "CYProjectDetailViewController.h"
#import "UIImageView+AFNetworking.h"
#import <CommonCrypto/CommonDigest.h>

@interface CYArcitleDetailsViewController ()<UITableViewDelegate, UITableViewDataSource, WKNavigationDelegate, HPGrowingTextViewDelegate, PlatformButtonClickDelegate, UIScrollViewDelegate>

@property (nonatomic, assign) CGFloat inputViewHeight;
@property (nonatomic, assign) BOOL commentOrReply;
@property (nonatomic, strong) NSNumber *huifuId;
@property (nonatomic, strong) NSNumber *userid;
@property (nonatomic, strong) UIButton *bottomCollectionBtn;
@property (nonatomic, strong) UIButton *bottomZanBtn;
@property (nonatomic, strong) UIImage *shareImage;

@property (nonatomic,strong) WKWebView *WKWebView;
@property (nonatomic,strong) CALayer *progresslayer;
@property (nonatomic, strong) CYProjectModel *detailModel;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *hotBusinessArr;
@property (nonatomic, strong) NSMutableArray *relatedInformationArr;
@property (nonatomic, strong) NSMutableArray *hotNewsArr;
@property (nonatomic, strong) NSMutableArray *commentArr;
@property (nonatomic, strong) CYProjectModel *adverModel;

@property (nonatomic, assign) CGFloat htmlCellHeight;

@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIView *inputView;
@property (nonatomic, strong) HPGrowingTextView *growingTextView;

@property (nonatomic, strong) NSMutableArray *allInfoArr;

@end

@implementation CYArcitleDetailsViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.tableView reloadData];
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = NO;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    IQKeyboardManager *manager = [IQKeyboardManager sharedManager];
    manager.enable = YES;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"资讯详情";
    self.inputViewHeight = 50;
    
//    if (self.content) {
////        [self.WKWebView loadHTMLString:self.content baseURL:[NSURL URLWithString:HOST]];
//        NSArray *arrs = [self filterTheImgUrlArrFromfahterHtml:self.content];
////        NSLog(@"arrs ---- %@",arrs);
//        NSMutableArray *muArr = [NSMutableArray arrayWithCapacity:0];
//        NSArray *value = [self.content componentsSeparatedByString:@"<span"];
//        NSString *html = @"";
//        for (NSString *str in value) {
//            NSString *result = [NSString stringWithFormat:@"<span%@",str];
//            if (![result containsString:@"<img"]) {
//                [muArr addObject:result];
//                html = [html stringByAppendingPathComponent:result];
//            }
//        }
//        NSLog(@"muArr ---- %@",muArr);
//
//        [self.WKWebView loadHTMLString:html baseURL:[NSURL URLWithString:HOST]];
//    }
    [self getDetail];
    [self getTuiJian];
    [self getComment];
    [self RightsetupNavgationItemWithpictureName:@"zxxq_gengd"];
    self.tableView.estimatedRowHeight = 0;
    if (@available(iOS 11.0, *)) {
        self.tableView.estimatedSectionFooterHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == self.tableView) {
        [self.WKWebView setNeedsLayout];
    }
}

- (NSArray *)filterTheImgUrlArrFromfahterHtml:(NSString *)html{
    ///<img|IMG)[^\<\>]*>找img标签的正则
    //    NSString *ss = @"<(img|IMG)[^\\<\\>]*>";//img标签的正则表达式
    NSString *ss = @"<img\\b.*?(?:\\>|\\/>)";//img标签的正则表达式
    //    NSString *ss = @"/\"([^\"]*)\"/";//img标签的正则表达式
    NSString *subHtml = html;
    NSMutableArray *muArr = [NSMutableArray arrayWithCapacity:0];
    while (subHtml.length != 0) {
        NSRegularExpression *pre = [[NSRegularExpression alloc] initWithPattern:ss options:0 error:nil];
        NSArray *arr = [pre matchesInString:subHtml options:NSMatchingReportProgress range:NSMakeRange(0, subHtml.length)];//这个方法匹配正则，找到符合的结果返回数组集合，返回的类型是NSTextCheckingResult下面会提到。
        NSLog(@"arr - %@",arr);
        if (arr.count > 0) {
            NSTextCheckingResult *match = [arr firstObject];
            NSRange matchRange = [match range];//返回的是每个imgb标签的位置
            //截取文本
            NSString *title = [subHtml substringWithRange:NSMakeRange(0, matchRange.location)];
            [muArr addObject:title];
            
            NSString *imgDivStr = [html substringWithRange:matchRange];//根据位置找对应img标签
            
            imgDivStr = [imgDivStr stringByReplacingOccurrencesOfString:@" " withString:@""];
            //此处我为了找出图片URL过滤掉空格
            
            NSString *imgUrl = [[imgDivStr componentsSeparatedByString:@"src=\""] lastObject];
            imgUrl = [[imgUrl componentsSeparatedByString:@"\""] firstObject];
            NSString *imgstr = [NSString stringWithFormat:@"<img>%@",imgUrl];
            [muArr addObject:imgstr];
            subHtml = [NSMutableString stringWithString:[subHtml substringWithRange:NSMakeRange(matchRange.location + matchRange.length, subHtml.length - matchRange.location - matchRange.length)]];
        }else{
            //截取文本
            NSString *title = [subHtml substringWithRange:NSMakeRange(0, subHtml.length)];
            [muArr addObject:title];
            subHtml = @"";
        }
    }
    return [NSArray arrayWithArray:muArr];
}

- (void)RighttouchEvent{
    YSActionSheetView * ysSheet=[[YSActionSheetView alloc]initNYSView];
    ysSheet.delegate=self;
    [[UIApplication sharedApplication].keyWindow addSubview:ysSheet];
}

- (void) customActionSheetButtonClick:(YSActionSheetButton *) btn
{
    [self shareImageToPlatformType:btn.tag];
}

- (void)shareImageToPlatformType:(NSInteger)platformType
{
    //2:qq 3:qzone 0:weixin 1:pengyouquan
    //创建分享消息对象
    if (platformType == 2 || platformType == 3) {
        
        NSString *utf8String = self.detailModel.share_url;
        NSString *title = self.detailModel.title;
        NSString *description = self.detailModel.shareContent;
        UIImage *image = nil;
        if (!self.shareImage) {
            image = [UIImage imageNamed:@"login_logo"];
        }else{
            image = self.shareImage;
        }
        QQApiNewsObject *newsObj = [QQApiNewsObject
                                    objectWithURL:[NSURL URLWithString:utf8String] title:title description:description previewImageData:UIImageJPEGRepresentation(image, 1)];
        SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
        if (platformType == 2) {
            //将内容分享到qq
            [QQApiInterface sendReq:req];
        }else{
            //将内容分享到qzone
            [QQApiInterface SendReqToQZone:req];
        }
        
    }else{
        SendMessageToWXReq *req1 = [[SendMessageToWXReq alloc]init];
        // 是否是文档
        req1.bText =  NO;
        
        //    WXSceneSession  = 0,        /**< 聊天界面    */
        //    WXSceneTimeline = 1,        /**< 朋友圈      */
        //    WXSceneFavorite = 2,
        
        
        req1.scene = (int)platformType;
        
        //创建分享内容对象
        WXMediaMessage *urlMessage = [WXMediaMessage message];
        urlMessage.title = self.detailModel.title;//分享标题
        urlMessage.description = self.detailModel.shareContent;//分享描述
        if (!self.shareImage) {
            [urlMessage setThumbImage:[UIImage imageNamed:@"login_logo"]];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
        }else{
            [urlMessage setThumbImage:self.shareImage];//分享图片,使用SDK的setThumbImage方法可压缩图片大小
        }
        
        //创建多媒体对象
        WXWebpageObject *webObj = [WXWebpageObject object];
        webObj.webpageUrl = self.detailModel.share_url;//分享链接
        
        //完成发送对象实例
        urlMessage.mediaObject = webObj;
        req1.message = urlMessage;
        
        //发送分享信息
        [WXApi sendReq:req1];
        
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3 + self.allInfoArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0 || section == 1) {
        return 1;
    }else if(section == 3 + self.allInfoArr.count - 1){
        return self.commentArr.count;
    }else{
        if (self.allInfoArr.count == 0) {
            return self.commentArr.count;
        }else{
            id obj = self.allInfoArr[section - 2];
            if (obj == self.relatedInformationArr) {
                return 1;
            }else if (obj == self.adverModel){
                return 1;
            }else if (obj == self.hotBusinessArr){
                return self.hotBusinessArr.count;
            }else{
                return self.hotNewsArr.count;
            }
        }
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    __weak typeof(self)weakself = self;
    if (indexPath.section == 0) {
        CYZiXunTitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYZiXunTitleTableViewCell"];
        if (!cell) {
            cell = [[NSBundle mainBundle] loadNibNamed:@"CYZiXunTitleTableViewCell" owner:nil options:nil][0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.model = self.detailModel;
        cell.block = ^{
            if ([weakself.detailModel.is_follow integerValue] == 1) {
                [weakself cancleguanzhu];
            }else{
                [weakself guanzhu];
            }
        };
        return cell;
    }else if (indexPath.section == 1){
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"htmlCell"];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"htmlCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.WKWebView removeFromSuperview];
        self.WKWebView.frame = CGRectMake(0, 0, kWindowW, self.htmlCellHeight);
        [cell.contentView addSubview:self.WKWebView];
        return cell;
    }else if(indexPath.section == 3 + self.allInfoArr.count - 1){
        CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
        if (!cell) {
            cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_CommentTableViewCell" owner:nil options:nil][0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        CYCommentModel *comment = self.commentArr[indexPath.row];
        cell.commentModel = comment;
        cell.block = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
            weakself.commentOrReply = NO;
            weakself.huifuId = commentId;
            weakself.userid = userId;
            [weakself.growingTextView becomeFirstResponder];
            
        };
        cell.zanblock = ^(NSNumber * _Nonnull userId, NSNumber * _Nonnull commentId) {
            if ([comment.isLike integerValue] == 1) {
                [weakself cancleZanWithCommentModel:comment];
            }else{
                [weakself zanWithCommentModel:comment];
            }
        };
        return cell;
    }else{
        id obj = self.allInfoArr[indexPath.section - 2];
        if (obj == self.relatedInformationArr) {
            CYZiXunXiangGuanSouSuoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYZiXunXiangGuanSouSuoTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYZiXunXiangGuanSouSuoTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.contentArr = self.relatedInformationArr;
            
            return cell;
        }else if (obj == self.adverModel){
            CYZiXunXiangGuanGuangGaoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYZiXunXiangGuanGuangGaoTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYZiXunXiangGuanGuangGaoTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.adverModel;
            return cell;
        }else if (obj == self.hotNewsArr){
            CYVideoDetail_ShipinTuiJianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYVideoDetail_ShipinTuiJianTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYVideoDetail_ShipinTuiJianTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.hotnewsmodel = self.hotNewsArr[indexPath.row];
            return cell;
        }else{
            CYZiXunXiangGuanXiangMuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CYZiXunXiangGuanXiangMuTableViewCell"];
            if (!cell) {
                cell = [[NSBundle mainBundle] loadNibNamed:@"CYZiXunXiangGuanXiangMuTableViewCell" owner:nil options:nil][0];
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.model = self.hotBusinessArr[indexPath.row];
            return cell;
        }
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        CGFloat height = [[Tool sharedInstance] heightForString:self.detailModel.title andWidth:kWindowW - 30 fontSize:20];
        return 90 + height;
    }else if (indexPath.section == 1){
        return self.htmlCellHeight;
    }else if(indexPath.section == 3 + self.allInfoArr.count - 1){
        CYVideoDetail_CommentTableViewCell *cell = [CYVideoDetail_CommentTableViewCell initWithTableView:tableView Identifier:@"CYVideoDetail_CommentTableViewCell"];
        cell.commentModel = self.commentArr[indexPath.row];
        return cell.cellHeight;
    }else{
        id obj = self.allInfoArr[indexPath.section - 2];
        if (obj == self.relatedInformationArr) {
            return 158;
        }else if (obj == self.adverModel){
            return 270;
        }else if (obj == self.hotNewsArr){
            return 114;
        }else{
            CYProjectModel *model = self.hotBusinessArr[indexPath.row];
            UIView *view = [[Tool sharedInstance] setSignView:model.mode andBackgroundColor:RGBOF(0xF5F7FB) andTitleColor:RGBOF(0x97A2B9) Height:20 andFont:[UIFont systemFontOfSize:12] andMargin_x:8 andMargin_y:8 andMaxWidth:kWindowW - 145];
            return 135 + view.frame.size.height;
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0 || section == 1) {
        return 0.0001f;
    }else if(section == 3 + self.allInfoArr.count - 1){
        return 40;
    }else{
        id obj = self.allInfoArr[section - 2];
        if (obj == self.relatedInformationArr) {
            return 0.0001f;
        }else if (obj == self.adverModel){
            return 0.0001f;
        }else if (obj == self.hotBusinessArr){
            return 40;
        }else{
            return 40;
        }
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    [view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    if (section == 0 || section == 1) {
        return view;
    }else if(section == 3 + self.allInfoArr.count - 1){
        UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
        view1.backgroundColor = [UIColor redColor];
        [view addSubview:view1];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
        label.textColor = RGBOF(0x333333);
        label.font = [UIFont systemFontOfSize:15];
        label.text = [NSString stringWithFormat:@"评论%ld",self.commentArr.count];
        [view addSubview:label];
        return view;
    }else{
        id obj = self.allInfoArr[section - 2];
        if (obj == self.relatedInformationArr) {
            return view;
        }else if (obj == self.adverModel){
            return view;
        }else if (obj == self.hotNewsArr){
            UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
            view1.backgroundColor = [UIColor redColor];
            [view addSubview:view1];
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
            label.textColor = RGBOF(0x333333);
            label.font = [UIFont systemFontOfSize:15];
            label.text = @"热门资讯";
            [view addSubview:label];
            
            UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
            more.frame = CGRectMake(kWindowW - 70, 5, 55, 30);
            [more setTitle:@"更多 >" forState:UIControlStateNormal];
            [more setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
            more.titleLabel.font = [UIFont systemFontOfSize:12];
            [view addSubview:more];
            [more addTarget:self action:@selector(zixunmoreAction:) forControlEvents:UIControlEventTouchUpInside];
            return view;
        }else{
            UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(15, 12, 2, 16)];
            view1.backgroundColor = [UIColor redColor];
            [view addSubview:view1];
            
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view1.frame) + 10, 12, 100, 16)];
            label.textColor = RGBOF(0x333333);
            label.font = [UIFont systemFontOfSize:15];
            label.text = @"热门商机";
            [view addSubview:label];
            
            UIButton *more = [UIButton buttonWithType:UIButtonTypeCustom];
            more.frame = CGRectMake(kWindowW - 70, 5, 55, 30);
            [more setTitle:@"更多 >" forState:UIControlStateNormal];
            [more setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
            more.titleLabel.font = [UIFont systemFontOfSize:12];
            [view addSubview:more];
            [more addTarget:self action:@selector(shangjiAction:) forControlEvents:UIControlEventTouchUpInside];
            return view;
        }
    }
    
}

- (void)zixunmoreAction:(UIButton *)sender{
    [self.tabBarController setSelectedIndex:0];
    [self.navigationController popToRootViewControllerAnimated:NO];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"gotoZiXun" object:nil];
}

- (void)shangjiAction:(UIButton *)sender{
    [self.tabBarController setSelectedIndex:1];
    [self.navigationController popToRootViewControllerAnimated:NO];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 0 || section == 2) {
        return 0.0001f;
    }
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        
    }else if (indexPath.section == 1){
        
    }else if(indexPath.section == 3 + self.allInfoArr.count - 1){
        //评论
    }else{
        id obj = self.allInfoArr[indexPath.section - 2];
        if (obj == self.relatedInformationArr) {
            
        }else if (obj == self.adverModel){
            CYProjectDetailViewController *detail = [[CYProjectDetailViewController alloc] init];
            detail.model = self.adverModel;
            [[AppDelegate sharedAppDelegate] pushViewController:detail];
        }else if (obj == self.hotNewsArr){
            CYProjectModel *model = self.hotNewsArr[indexPath.row];
            CYArcitleDetailsViewController *detail = [[CYArcitleDetailsViewController alloc] init];
            detail.articleId = [model.ID stringValue];
            [[AppDelegate sharedAppDelegate] pushViewController:detail];
        }else{
            CYProjectDetailViewController *detail = [[CYProjectDetailViewController alloc] init];
            detail.model = self.hotBusinessArr[indexPath.row];
            [[AppDelegate sharedAppDelegate] pushViewController:detail];
        }
    }
}

#pragma mark - WKWebViewDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
    //    1.拦截请求
    NSString *urlString = [navigationAction.request.URL absoluteString];
    NSLog(@"urlString -- %@",urlString);
    if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
        //跳转别的应用如系统浏览器
        // 对于跨域，需要手动跳转
        [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
        // 不允许web内跳转
        decisionHandler(WKNavigationActionPolicyCancel);
        
    } else {
        //应用的web内跳转
        decisionHandler (WKNavigationActionPolicyAllow);
        
    }
    return ;//不添加会崩溃

}

- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
    NSLog(@"start --- %@",webView.URL);
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
    NSLog(@"jiazaiwanbi");
    __weak typeof(self)weakself = self;
    [webView evaluateJavaScript:@"document.body.offsetHeight;" completionHandler:^(id _Nullable any, NSError * _Nullable error) {
        NSString *heightStr = [NSString stringWithFormat:@"%@",any];
        weakself.htmlCellHeight = [heightStr floatValue] + 15;
        [weakself.view addSubview:weakself.tableView];
        NSLog(@"heightStr -- %@",heightStr);
        [weakself.view addSubview:weakself.bottomView];
        [weakself.view addSubview:weakself.inputView];
        [weakself.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(weakself.view).with.mas_equalTo(weakself.inputViewHeight);
            make.left.equalTo(weakself.view).with.mas_offset(0);
            make.right.equalTo(weakself.view).with.mas_offset(0);
            make.height.mas_equalTo(weakself.inputViewHeight);
        }];
    }];
}
-(WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures

{
    NSLog(@"createWebViewWithConfiguration");
    if (!navigationAction.targetFrame.isMainFrame) {
        [webView loadRequest:navigationAction.request];
    }
    return nil;
    
}


// 观察者
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    if ([keyPath isEqualToString:@"estimatedProgress"]) {
        self.progresslayer.opacity = 1;
        float floatNum = [[change objectForKey:@"new"] floatValue];
        self.progresslayer.frame = CGRectMake(0, 0, kWindowW * floatNum, 2);
        if (floatNum == 1) {
            
            __weak __typeof(self)weakSelf = self;
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                weakSelf.progresslayer.opacity = 0;
                
            });
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                weakSelf.progresslayer.frame = CGRectMake(0, 0, 0, 3);
            });
        }
        
    }else{
        
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
    
}


-(void)dealloc{
    [self.WKWebView removeObserver:self forKeyPath:@"estimatedProgress"];
}

#pragma mark - 新闻资讯详情
- (void)getDetail{
    NSString *url = [NSString stringWithFormat:@"%@%@",HOST, @"index/view"];
    NSDictionary *param = @{@"id":self.articleId, @"type":@"7"};

    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"新闻资讯详情 ---- %@",responseResult);
        if ([weakself.tableView.mj_header isRefreshing]) {
            [weakself.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                if ([responseResult[@"data"] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *data = responseResult[@"data"];
                    
                    weakself.detailModel = [CYProjectModel mj_objectWithKeyValues:data];
                    [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:weakself.detailModel.image] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
                        
                    } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
                        weakself.shareImage = image;
                    }];
                    
                    [weakself.WKWebView loadHTMLString:weakself.detailModel.content baseURL:[NSURL URLWithString:HOST]];

                    [weakself initBottomData];
                    [weakself.tableView reloadData];
                }
                
            }else{
                
            }
        }
    }];
}

- (void)initBottomData{
    if ([self.detailModel.is_like integerValue] == 2) {
        //未点赞
        self.bottomZanBtn.selected = NO;
    }else{
        //已点赞
        self.bottomZanBtn.selected = YES;
    }
    
    if ([self.detailModel.is_collect integerValue] == 2) {
        //未收藏
        self.bottomCollectionBtn.selected = NO;
    }else{
        //已收藏
        self.bottomCollectionBtn.selected = YES;
    }
}

- (void)getTuiJian{
    NSString *url = [NSString stringWithFormat:@"%@%@",HOST, @"recommend"];
    NSDictionary *param = @{@"id":self.articleId, @"type":@"7"};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取推荐 ---- %@",responseResult);
        if ([weakself.tableView.mj_header isRefreshing]) {
            [weakself.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                NSDictionary *data = responseResult[@"data"];
                [weakself.allInfoArr removeAllObjects];

                //相关搜索
                if ([data[@"relatedInformation"] isKindOfClass:[NSArray class]]) {
                    NSArray *relatedInformation = data[@"relatedInformation"];
                    if (relatedInformation.count > 0) {
                        [weakself.relatedInformationArr removeAllObjects];
                        for (NSDictionary *dic in relatedInformation) {
                            CYProjectModel *model = [CYProjectModel mj_objectWithKeyValues:dic];
                            [weakself.relatedInformationArr addObject:model];
                        }
                        [weakself.allInfoArr addObject:weakself.relatedInformationArr];
                    }
                }
                
                //广告
                if ([data[@"advertisement"] isKindOfClass:[NSDictionary class]]) {
                    NSDictionary *advertisement = data[@"advertisement"];
                    weakself.adverModel = [CYProjectModel mj_objectWithKeyValues:advertisement];
                    [weakself.allInfoArr addObject:weakself.adverModel];
                }
                
                //r热门商机
                if ([data[@"hotBusiness"] isKindOfClass:[NSArray class]]) {
                    NSArray *hotBusiness = data[@"hotBusiness"];
                    if (hotBusiness.count > 0) {
                        [weakself.hotBusinessArr removeAllObjects];
                        for (NSDictionary *dic in hotBusiness) {
                            CYProjectModel *model = [CYProjectModel mj_objectWithKeyValues:dic];
                            [weakself.hotBusinessArr addObject:model];
                        }
                        [weakself.allInfoArr addObject:weakself.hotBusinessArr];
                    }
                }
                
                //热门资讯
                if ([data[@"hotNews"] isKindOfClass:[NSArray class]]) {
                    NSArray *hotNews = data[@"hotNews"];
                    if (hotNews.count > 0) {
                        [weakself.hotNewsArr removeAllObjects];
                        for (NSDictionary *dic in hotNews) {
                            CYProjectModel *model = [CYProjectModel mj_objectWithKeyValues:dic];
                            [weakself.hotNewsArr addObject:model];
                        }
                        [weakself.allInfoArr addObject:weakself.hotNewsArr];

                    }
                }
                [weakself.tableView reloadData];
            }else{
                
            }
        }
    }];
}

- (void)getComment{
    self.page = 1;
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"comments"];
    NSDictionary *param = @{@"articleId":self.articleId, @"type":@"7", @"pageNo":@1, @"pageSize":@"10"};
    __weak typeof(self)weakself = self;
    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取评论 ---- %@",responseResult);
        if ([weakself.tableView.mj_header isRefreshing]) {
            [weakself.tableView.mj_header endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                NSDictionary *data = responseResult[@"data"];
                NSDictionary *comments = data[@"comments"];
                [weakself.commentArr removeAllObjects];
                for (NSDictionary *dic in comments) {
                    CYCommentModel *model = [CYCommentModel modelWithDictionary:dic];
                    [weakself.commentArr addObject:model];
                }
                [weakself.tableView reloadData];
            }else{
                
            }
        }
    }];
}

- (void)getMoreComment{
    self.page ++;
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"comments"];
    NSDictionary *param = @{@"articleId":self.articleId, @"type":@"7", @"pageNo":[NSNumber numberWithInteger:self.page], @"pageSize":@"10"};
    __weak typeof(self)weakself = self;

    [[XBRequest sharedInstance] getDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"获取评论 ---- %@",responseResult);
        if ([weakself.tableView.mj_footer isRefreshing]) {
            [weakself.tableView.mj_footer endRefreshing];
        }
        if ([responseResult objectForKey:@"resError"]) {
            [weakself.view makeToast:ResErrorMessage];
            weakself.page --;
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                NSDictionary *data = responseResult[@"data"];
                NSDictionary *comments = data[@"comments"];
                for (NSDictionary *dic in comments) {
                    CYCommentModel *model = [CYCommentModel modelWithDictionary:dic];
                    [weakself.commentArr addObject:model];
                }
                [weakself.tableView reloadData];
            }else{
                weakself.page --;
            }
        }
    }];
}

- (WKWebView *)WKWebView{
    if (!_WKWebView) {
        
        NSString *jScript =@"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta); var imgs = document.getElementsByTagName('img');for (var i in imgs){imgs[i].style.maxWidth='100%';imgs[i].style.height='auto';}";
        
        WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
        WKUserContentController *wkUController = [[WKUserContentController alloc] init];
        [wkUController addUserScript:wkUScript];
        
        WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
        
        wkWebConfig.userContentController = wkUController;
        
        _WKWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 0) configuration:wkWebConfig];
        _WKWebView.navigationDelegate = self;
        _WKWebView.opaque = NO;
        _WKWebView.backgroundColor = [UIColor clearColor];
        _WKWebView.scrollView.scrollEnabled = NO;
        self.progresslayer = [[CALayer alloc]init];
        self.progresslayer.frame = CGRectMake(0, 0, kWindowW * 0.1, 2);
        self.progresslayer.backgroundColor = RGBOF(0x0888D0).CGColor;
        [self.view.layer addSublayer:self.progresslayer];
        
        [_WKWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
    }
    return _WKWebView;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, kWindowH - Height_NavBar - self.bottomView.frame.size.height) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = BackGroundColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self getTuiJian];
            [self getDetail];
            [self getComment];
        }];
        _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
            [self getMoreComment];
        }];
        
        [_tableView registerNib:[UINib nibWithNibName:@"CYZiXunTitleTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYZiXunTitleTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYZiXunXiangGuanSouSuoTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYZiXunXiangGuanSouSuoTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYZiXunXiangGuanGuangGaoTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYZiXunXiangGuanGuangGaoTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYZiXunXiangGuanXiangMuTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYZiXunXiangGuanXiangMuTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYVideoDetail_ShipinTuiJianTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYVideoDetail_ShipinTuiJianTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"CYVideoDetail_CommentTableViewCell" bundle:nil] forCellReuseIdentifier:@"CYVideoDetail_CommentTableViewCell"];

    }
    return _tableView;
}

- (NSMutableArray *)hotNewsArr{
    if (!_hotNewsArr) {
        _hotNewsArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _hotNewsArr;
}

- (NSMutableArray *)hotBusinessArr{
    if (!_hotBusinessArr) {
        _hotBusinessArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _hotBusinessArr;
}

- (NSMutableArray *)relatedInformationArr{
    if (!_relatedInformationArr) {
        _relatedInformationArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _relatedInformationArr;
}

- (NSMutableArray *)commentArr{
    if (!_commentArr) {
        _commentArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _commentArr;
}

- (UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = [UIColor whiteColor];
        if (HX_IS_IPhoneX_All) {
            _bottomView.frame = CGRectMake(0, kWindowH - Height_NavBar - 83, kWindowW, 83);
        }else{
            _bottomView.frame = CGRectMake(0, kWindowH - Height_NavBar - 48, kWindowW, 48);
        }
        
        UIView *contrainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWindowW, 48)];
        [_bottomView addSubview:contrainerView];
        
        
        
        NSArray *images = @[@"ksp_pl", @"ksp_sc", @"ksp_zan"];
        CGFloat width = 20;
        CGFloat height = 20;
        UIButton *comBtn = nil;
        for (int i = 2; i >= 0; i--) {
            UIButton *commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [commentBtn setFrame:CGRectMake(kWindowW - 25 - 20 - (2 - i) * width - (2 - i) * 25, 12, width, height)];
            [commentBtn setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];
            [commentBtn addTarget:self action:@selector(btnsClick:) forControlEvents:UIControlEventTouchUpInside];
            [contrainerView addSubview:commentBtn];
            commentBtn.tag = i;
            if (i == 1) {
                self.bottomCollectionBtn = commentBtn;
                [commentBtn setImage:[UIImage imageNamed:@"video_collect_selected"] forState:UIControlStateSelected];
            }
            if (i == 2) {
                self.bottomZanBtn = commentBtn;
                [commentBtn setImage:[UIImage imageNamed:@"zan_sel"] forState:UIControlStateSelected];
            }
            if (i == 0) {
                comBtn = commentBtn;
            }
        }
        
        UIButton *commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [commentBtn setFrame:CGRectMake(15, 9, CGRectGetMinX(comBtn.frame) - 30, 30)];
        commentBtn.layer.cornerRadius = 15;
        commentBtn.layer.borderWidth = 1;
        commentBtn.layer.borderColor = RGBOF(0xe3e3e3).CGColor;
        commentBtn.layer.masksToBounds = YES;
        [commentBtn setBackgroundColor:RGBOF(0xf7f7f7)];
        [commentBtn setTitle:@"   写评论" forState:UIControlStateNormal];
        [commentBtn setImage:[UIImage imageNamed:@"wd_wdwd"] forState:UIControlStateNormal];
        [commentBtn setTitleColor:RGBOF(0x999999) forState:UIControlStateNormal];
        commentBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        commentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [commentBtn setContentEdgeInsets:UIEdgeInsetsMake(0, 25, 0, 0)];
        [commentBtn addTarget:self action:@selector(commentAction) forControlEvents:UIControlEventTouchUpInside];
        [contrainerView addSubview:commentBtn];
    }
    return _bottomView;
}

#pragma mark - 关注
- (void)guanzhu{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"attention"];
    NSDictionary *param = @{@"toUserId":self.detailModel.user_id};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"添加关注 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            [[UIApplication sharedApplication].keyWindow makeToast:ResErrorMessage duration:1.5 position:CSToastPositionCenter];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
//                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                [self getDetail];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

- (void)cancleguanzhu{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@/%@",User_HOST, @"attention", self.detailModel.user_id];
    NSDictionary *param = @{@"userId":self.detailModel.user_id};
    [[XBRequest sharedInstance] deleteDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        NSLog(@"取消关注 ---- %@",responseResult);
        [EasyShowLodingView hidenLoding];
        if ([responseResult objectForKey:@"resError"]) {
            [[UIApplication sharedApplication].keyWindow makeToast:ResErrorMessage duration:1.5 position:CSToastPositionCenter];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
//                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                [self getDetail];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

#pragma mark - 评论
- (void)commentAction{
    self.commentOrReply = YES;
    [self.growingTextView becomeFirstResponder];
}

#pragma mark - 底部按钮的点赞，收藏
- (void)btnsClick:(UIButton *)sender{
    if (sender.tag == 0) {
        //评论
        [self commentAction];
    }else if (sender.tag == 1){
        //收藏
        if ([self.detailModel.is_collect integerValue] == 1) {
            //一收藏
            [self cancleCollection];
        }else{
            [self collection];
        }
    }else{
        //点赞
        if ([self.detailModel.is_like integerValue] == 1) {
            [self cancleZanWenZhang];
        }else{
            [self zanWenZhang];
        }
    }
}

#pragma mark - 收藏取消收藏
- (void)cancleCollection{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@/%@",User_HOST, @"collection",self.detailModel.ID];
    NSDictionary *param = @{@"type":@"7", @"articleId":self.detailModel.ID};
    [[XBRequest sharedInstance] deleteDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"取消收藏 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [self getDetail];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];

            }
        }
    }];
}

- (void)collection{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"collection/addCollect"];
    NSDictionary *param = @{@"type":@7, @"articleId":self.detailModel.ID};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"收藏本咨询 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [self getDetail];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];

            }
        }
    }];
}

#pragma mark - 给文章赞和取消点赞
- (void)zanWenZhang{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"addLike"];
    NSDictionary *param = @{@"type":@1, @"likeId":self.detailModel.ID, @"origin":@"7", @"toLikerId":self.detailModel.user_id};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"给文章点赞 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [self getDetail];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}
- (void)cancleZanWenZhang{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"cancleLike"];
    NSDictionary *param = @{@"type":@1, @"articleId":self.detailModel.ID, @"origin":@"7", @"toLikerId":self.detailModel.user_id};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"给文章取消点赞 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [self getDetail];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}
#pragma mark - 给评论赞和取消点赞
- (void)cancleZanWithCommentModel:(CYCommentModel *)commentModel{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"cancleLike"];
    NSDictionary *param = @{@"type":@2, @"articleId":commentModel.ID, @"origin":@"7", @"toLikerId":commentModel.userId};

    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"取消点赞 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                commentModel.isLike = [NSNumber numberWithInteger:2];
                NSInteger tag = [commentModel.likeNumber integerValue];
                commentModel.likeNumber = [NSString stringWithFormat:@"%ld",(tag - 1)];
                [self.tableView reloadData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];

            }
        }
    }];
}

- (void)zanWithCommentModel:(CYCommentModel *)commentModel{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"addLike"];
    NSDictionary *param = @{@"type":@2, @"likeId":commentModel.ID, @"origin":@"7", @"toLikerId":commentModel.userId};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"赞评论 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                commentModel.isLike = [NSNumber numberWithInteger:1];
                NSInteger tag = [commentModel.likeNumber integerValue];
                commentModel.likeNumber = [NSString stringWithFormat:@"%ld",(tag + 1)];
                [self.tableView reloadData];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
            }
        }
    }];
}

#pragma mark - 发布评论
- (void)fasongpinglunWithText:(NSString *)content{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"comment"];
    NSDictionary *param = @{@"toUserId":self.detailModel.user_id, @"type":@"7", @"articleId":self.articleId, @"content":content};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"发布评论 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [self getComment];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];

            }
        }
    }];
}

#pragma mark - 发布回复
- (void)fasongHuiFuWithText:(NSString *)content{
    if (![YLUserInfo isLogIn]) {
        LoginViewController *login = [[LoginViewController alloc] init];
        [[AppDelegate sharedAppDelegate] pushViewController:login];
        return;
    }
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",User_HOST, @"inserReply"];
    NSDictionary *param = @{@"toUserId":self.userid, @"type":@"7", @"commentId":self.huifuId, @"content":content};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"发布回复 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [self getComment];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];

            }
        }
    }];
}

- (UIView *)inputView{
    if (!_inputView) {
        _inputView = [[UIView alloc] init];
        _inputView.backgroundColor = [UIColor whiteColor];
        HPGrowingTextView *group = [[HPGrowingTextView alloc] init];
        self.growingTextView = group;
        group.delegate = self;
        group.font = [UIFont systemFontOfSize:14];
        group.minNumberOfLines = 1;
        group.maxNumberOfLines = 5;
        group.placeholder = @"输入评论";
        group.returnKeyType = UIReturnKeySend;
        group.enablesReturnKeyAutomatically = YES;
        group.backgroundColor = RGBOF(0xf6f6f6);
        group.layer.cornerRadius = 5;
        [_inputView addSubview:group];
        [group mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self->_inputView).with.mas_offset(10);
            make.top.equalTo(self->_inputView).with.mas_offset(5);
            make.right.equalTo(self->_inputView).with.mas_offset(-10);
            make.bottom.equalTo(self->_inputView).with.mas_offset(-5);
            
        }];
    }
    return _inputView;
}

#pragma mark - UIKeyboardNotification

- (void)keyboardWillShow:(NSNotification *)notification
{
    CGRect endRect = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
    NSLog(@"keyboardWillShow -- %f",endRect.size.height);
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view).with.mas_equalTo(-endRect.size.height);
            make.left.equalTo(self.view).with.mas_offset(0);
            make.right.equalTo(self.view).with.mas_offset(0);
            make.height.mas_equalTo(self.inputViewHeight);
        }];
        [self.view layoutIfNeeded];
    } completion:nil];
}

- (void)keyboardWillHide:(NSNotification *)notification
{
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view).with.mas_equalTo(self.inputViewHeight);
        }];
        [self.view layoutIfNeeded];
    } completion:nil];
}

#pragma mark - UITextViewDelegate

- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height
{
    self.inputViewHeight = height + 14;
    [self.inputView mas_updateConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(height + 14);
    }];
    [self.view layoutIfNeeded];
}

- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView
{
    [self.growingTextView resignFirstResponder];
    return YES;
}

- (BOOL)growingTextView:(HPGrowingTextView *)growingTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    //判断是回车键就发送出去
    if ([text isEqualToString:@"\n"])
    {
        if (self.commentOrReply) {
            [self fasongpinglunWithText:self.growingTextView.text];
        }else{
            [self fasongHuiFuWithText:self.growingTextView.text];
        }
        self.growingTextView.text = @"";
        [self.growingTextView resignFirstResponder];
        [self.tableView reloadData];
        return NO;
    }
    return YES;
}

- (void)growingTextViewDidChange:(HPGrowingTextView *)growingTextView
{
    UITextRange *selectedRange = growingTextView.internalTextView.markedTextRange;
    NSString *newText = [growingTextView.internalTextView textInRange:selectedRange];
    
    if (newText.length < 1)
    {
        // 高亮输入框中的@
        UITextView *textView = self.growingTextView.internalTextView;
        NSRange range = textView.selectedRange;
        
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:textView.text];
        [string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, string.string.length)];
        
        
        textView.attributedText = string;
        textView.selectedRange = range;
    }
}

- (void)growingTextViewDidChangeSelection:(HPGrowingTextView *)growingTextView
{
    // 光标不能点落在@词中间
    NSRange range = growingTextView.selectedRange;
    if (range.length > 0)
    {
        // 选择文本时可以
        return;
    }
    
}

- (NSMutableArray *)allInfoArr{
    if (!_allInfoArr) {
        _allInfoArr = [NSMutableArray arrayWithCapacity:0];
    }
    return _allInfoArr;
}

@end
